package com.ccys.app.service.impl;

import com.ccys.app.service.PaymentDetailService;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.dto.app.paymentDetails.CalculationCostDto;
import com.ccys.db.mapper.TblSupplierMapper;
import com.ccys.db.vo.app.paymentDetails.CalculationCostVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * @Author：XLY
 * @Date：2024/2/4 0004
 */
@Service
public class PaymentDetailServiceImpl implements PaymentDetailService {

    @Resource
    private TblSupplierMapper mapper;

    @Override
    public CalculationCostVo calculationCost(CalculationCostDto dto) {
        String booking_id = dto.getBooking_id();
        if(StringUtils.isNotEmpty(booking_id)){
            CalculationCostVo res = mapper.calculationCost(booking_id);

            //生成tax对象
            CalculationCostVo.TaxVo taxVo = new CalculationCostVo.TaxVo();
            BigDecimal taxRate = res.getTaxRate();
            taxVo.setAmount(taxRate);
            taxVo.setType("percent");
            BigDecimal grandTotal = res.getGrandTotal();
            taxVo.setFee(new BigDecimal(0));
            if(Objects.nonNull(grandTotal)&&Objects.nonNull(taxRate)){
                BigDecimal taxAmount = grandTotal.multiply(taxRate);
                taxVo.setFee(taxAmount);
            }
            res.setTax(taxVo);


            //生成serviceType对象
            BigDecimal serviceTypeFee = res.getServiceTypeFee();
            boolean showInBill = res.isShowInBill();
            CalculationCostVo.MedicalServiceTypeVo serviceTypeVo = new CalculationCostVo.MedicalServiceTypeVo();
            serviceTypeVo.setShowInBill(showInBill);
            serviceTypeVo.setPrice(serviceTypeFee);
            res.setMedicalServiceType(serviceTypeVo);

            // TODO: 2024/2/4 0004 部分字段不清楚

            // TODO: 2024/2/4 0004 delivery address 是一个集合 。。
            dto.setDelivery_type(dto.getDelivery_type());

            return res;
        }

        return null;
    }
}
